<template>
  <div class="gooods-sift-container">
    <div :class="{ active: type === 'all' }" @touchend="changeType('all')">综合</div>
    <div :class="{ active: type === 'sell' }" @touchend="changeType('sell')">销量</div>
    <div
      class="price"
      :class="{
        'price-up active': type === 'price-up',
        'price-down active': type === 'price-down',
      }"
      @touchend="changeType('price')"
    >
      价格
    </div>
  </div>
</template>

<script>
import { mapState } from "vuex";
export default {
  data() {
    return {
      class: "",
    };
  },
  computed: {
    ...mapState(["type"]),
  },
  methods: {
    //设置筛选类型
    changeType(types) {
      if (types === "price") {
        if (this.class === "price-up") {
          this.class = "price-down";
        } else {
          this.class = "price-up";
        }
      } else if (types === "sell") {
        this.class = "sell";
      } else {
        this.class = "all";
      }
      this.$store.commit("setType", this.class);
    },
  },
};
</script>

<style lang="scss" scoped>
@import "../css/GoodsSift.scss";
</style>
